package com.taorui.ajax;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * Servlet implementation class MvcServlet
 */
@WebServlet(name = "CheckUserServlet1", urlPatterns = "/CheckUserServlet1", initParams = {
		@WebInitParam(name = "actionconfig", value = "action.properties") })
public class CheckUserServlet1 extends HttpServlet {
	private static final long serialVersionUID = 1L;
	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public CheckUserServlet1() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
	    	 try {
	                response.getWriter().print(this.checkUser(request, response));
	            } catch (SQLException e) {
	                e.printStackTrace();
	            } catch (ClassNotFoundException e) {
	                e.printStackTrace();
	            }
	}
	/**
	 * 验证登录用户名
	 * @param request
	 * @param response
	 * @return
	 * @throws SQLException
	 * @throws ClassNotFoundException
	 */
	 public String checkUser(HttpServletRequest request, HttpServletResponse response) throws SQLException, ClassNotFoundException {
	        String userName = request.getParameter("userName");
	        System.out.println("111");
	        if (userName.equals("ajax")) {
	            return "用户名已被使用";
	        } else {
	            return "用户名可以使用";
	        }
	    }
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
